package com.mnt.washio.adapters;

import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.mnt.washio.R;

public class ImageAdapter extends PagerAdapter {

	private Context mContext;
	private LayoutInflater inflater;
	private String[] objects;

	public ImageAdapter(Activity _context, String[] objects) {
		super();

		this.mContext = _context;
		this.objects = objects;
		this.inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	@Override
	public int getCount() {
		return objects.length;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager)container).removeView((View)object);
	}
	
	@Override
	public int getItemPosition(Object object) {
		return POSITION_NONE;
	}

	@Override
	public Object instantiateItem(View container, int position) {
		String draw = objects[position];

		ImageView v = (ImageView) inflater.inflate(
				R.layout.item_viewpager_image, null);
		final ImageView imv = (ImageView) v;

		int resId = mContext.getResources().getIdentifier(draw, "drawable",
				mContext.getPackageName());
		imv.setImageResource(resId);

		((ViewPager) container).addView(v);

		return v;
	}

}
